package io.renren.modules.pachong.controller;

import io.renren.common.utils.R;
import io.renren.modules.pachong.Movie;
import io.renren.modules.pachong.MovieTag;
import io.renren.modules.pachong.MovieTagVO;
import io.renren.modules.pachong.service.MovieService;
import io.renren.modules.pachong.service.QiSiMovieService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author Peter
 * @date 2018-8-10
 */
@RestController
@RequestMapping("/sys/movie")
public class MovieController {

    @Autowired
    private MovieService movieService;
    @Autowired
    private QiSiMovieService qiSiMovieService;

    @ApiOperation("新增电影标签")
    @RequestMapping(value = "/addTag", method = RequestMethod.GET)
    @ResponseBody
    public R addMovieTag() {
        try {
            movieService.addMovieTag();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok();
    }
    @ApiOperation("新增电影")
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    @ResponseBody
    public R addMovieData() {
        try {
            List<Movie> list = movieService.addMoive();
            if(list.size() == 0){
                return R.ok("没有可插入的数据");
            }
            Collections.reverse(list);
            movieService.insertBatch(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok();
    }

    @ApiOperation("新增骑士电影标签")
    @RequestMapping(value = "/addQiSiTag", method = RequestMethod.GET)
    @ResponseBody
    public R addQiSiMovieTag() {
        try {
            qiSiMovieService.addMovieTag();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok();
    }

    @ApiOperation("新增骑士电影")
    @RequestMapping(value = "/addQiSiMovie", method = RequestMethod.GET)
    @ResponseBody
    public R addQiSiMovie() {
        try {
            qiSiMovieService.addMovie();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok();
    }



    @ApiOperation("列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public R movieList(@RequestParam Map<String, Object> params) {
        List<Movie> page = movieService.queryPage(params);
        return R.ok().put("page", page);
    }


    @ApiOperation("电影标签列表")
    @RequestMapping(value = "/movieTagList", method = RequestMethod.POST)
    @ResponseBody
    public R selectAllMoiveTag() {
        List<MovieTagVO> list = movieService.selectAllMoiveTag();
        return R.ok().put("page", list);
    }
}
